# include "functions.h"
# include <time.h>
# include <stdio.h>
# include <math.h>

bool data[20];// 0-00-0000-00000000-
			  // aarde/cricked-opcode-id-afstand

//http://www.cplusplus.com/reference/clibrary/ctime/time/

void ReadPort(bool Recievebit[MESSAGELENGTH])
{
    bool *rs232_port = (bool*)0xC00000;//set memory

    for(int i=0;i<MESSAGELENGTH;i++)
    {
        Recievebit[i] = rs232_port[i]; /* read from port */
    }
}


void WritePort(bool Sendbit[MESSAGELENGTH])
{
    bool *rs232_port = (bool*)0xC00000;//set memory

    for(int i=0;i<MESSAGELENGTH;i++)
    {
        rs232_port[i] = Sendbit[i]; /* write to port */
    }
}

void rijden(int nummer){
	for(int i=0;i<20;i++){
		data[i]=1;
	}
	int buffer=nummer;
	int a=0;
	bool nr[4]={0,0,0,0};
	for(int i=4;i>0;i--){
		a=pow(2,float(i));
		buffer=buffer-a;
		if(buffer>=0){
			nr[4-i]=1;
		}
		else{
			buffer=buffer+a;
			nr[4-i]=0;
		}
			
	}
	data[0]=0;// voor de cricket
	data[1]=0;// opcode 00
	data[2]=0;
	data[3]=nr[3];// karretje id (4-bits)
	data[4]=nr[2];
	data[5]=nr[1];
	data[6]=nr[0];
	for(int i=0;i<7;i++){
		if(data[i])
			printf("1");
		else
			printf("0");
	}
	printf("\n");
}

void initialisatie(){
	for(int i=0;i<20;i++){
		data[i]=1;
	}
	data[0]=0;// voor de cricket
	data[1]=1;// opcode 00
	data[2]=0;

	for(int i=0;i<7;i++){
		if(data[i])
			printf("1");
		else
			printf("0");
	}
	printf("\n");
}

void main(){
	rijden(10);
	initialisatie();



}